{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fb566100f4c54cd887f9605e1d5afad9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, fps_meter=False, grid=[0.01014351503017541,…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Example usage of align() method:\n",
    "generate two random sets of points as 2 actors\n",
    "and align them using the Iterative Closest Point algorithm.\n",
    "\"\"\"\n",
    "from __future__ import division\n",
    "from random import uniform as u\n",
    "from vtkplotter import *\n",
    "\n",
    "vp = Plotter() # create the Plotter instance explicitly\n",
    "\n",
    "N1 = 15  # number of points of first set\n",
    "N2 = 15  # number of points of second set\n",
    "x = 1.0  # add some randomness\n",
    "\n",
    "pts1 = [(u(0, x),   u(0, x), u(0, x) +i) for i in range(N1)]\n",
    "pts2 = [(u(0, x)+3, u(0, x) + i/2. +2, u(0, x)+i+1) for i in range(N2)]\n",
    "\n",
    "act1 = Points(pts1, c=\"b\")\n",
    "act2 = Points(pts2, c=\"r\")\n",
    "vp += [act1, act2]\n",
    "\n",
    "# find best alignment between the 2 sets of Points, e.i. find\n",
    "# how to move act1 to best match act2\n",
    "alpts1 = alignICP(act1, act2).coordinates()\n",
    "\n",
    "for i in range(N1):  # draw arrows to see where points end up\n",
    "    vp += Arrow(pts1[i], alpts1[i], s=0.01, c=\"k\", alpha=0.2)\n",
    "\n",
    "vp += Points(alpts1, c=\"blue\")\n",
    "\n",
    "vp.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
